
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <stdio.h>
#include <sys/time.h>
#include "app_platform/cntl_info.h"
#include "app_platform/cgi_stub_cntl.h"
#include "../include/storageao_stub4web_allinone.h"
#include "erp/storage/po/stockpo_storage.h"	
#include "erp/storage/po/stockfilterpo_storage.h"	
#include <set>	
#include <map>	
#include <vector>	

using namespace erp::storage::ao;

void Init()
{       
	if(CCGI_STUB_CNTL->Initialize(true) != 0)
		std::cerr << "CCGI_STUB_CNTL->Init failed" << std::endl;
	CCGI_STUB_CNTL->setTimeout(5);
}
void TestAddStock()
{
	//TODO 如果使用配置中心来获取APP地址,请注释下行
	//CCGI_STUB_CNTL->setPeerAddr("172.25.34.123", 53101);

	//TODO 请设置用户Passport
	CCntlInfo oCntlInfo;
	oCntlInfo.setOperatorUin(1);
	oCntlInfo.setOperatorClientIP(0);
	oCntlInfo.setOperatorKey("stw3ymf9uk");
	//TODO 请设置路由值
	oCntlInfo.setRouteKey(88883687);
	std::string machineKey = "123";
	std::string source = "123";
	uint32_t sceneId = 123;
	uint32_t option = 0;
	erp::storage::po::CStockPo StockInfo;
	std::string inReserve = "";		
	std::string errmsg = "";		
	std::string outReserve = "";		
	uint64_t SysNo = 0;
	CStorageAoStub4Web oStub;

	//mock

	StockInfo.ddwContactSysNo = 1;
    StockInfo.ddwCreatorSysNo=1;
    StockInfo.ddwModifierSysNo =1;
    StockInfo.dwStockStatus = 1;
    StockInfo.strName = "dd";
    StockInfo.strPyCode ="dd";
    StockInfo.strStockID ="dd";
	StockInfo.strFullName ="d";


	// TODO:替换函数参数
    uint32_t dwResult = oStub.AddStock(
		oCntlInfo,
		machineKey,
		source,
		sceneId,
		option,
		StockInfo,
		inReserve,
		errmsg,
		outReserve,
		SysNo
  	);
    if(dwResult == 0)
	{
		std::cout << "Invoke OK!" << std::endl;
		printf("OK result[0x%x], time = %ld\n"
        , dwResult, oStub.GetLastConsumeTime());
	}
	else
    {
        printf("Error result[0x%x], time = %ld , errmsg = [%s]\n"
        , dwResult, oStub.GetLastConsumeTime(),oStub.GetLastErrMsg());
    }
}

void TestDeleteStock()
{
	//TODO 如果使用配置中心来获取APP地址,请注释下行
	//CCGI_STUB_CNTL->setPeerAddr("172.25.34.123", 53101);

	//TODO 请设置用户Passport
	CCntlInfo oCntlInfo;
	oCntlInfo.setOperatorUin(1);
	oCntlInfo.setOperatorClientIP(0);
	oCntlInfo.setOperatorKey("stw3ymf9uk");
	//TODO 请设置路由值
	oCntlInfo.setRouteKey(88883687);
	std::string machineKey = "123";
	std::string source = "123";
	uint32_t sceneId = 123;
	uint32_t option = 0;
	std::set<uint64_t > FStockSysNo;
	std::string inReserve = "";		
	std::string errmsg = "";		
	std::map<uint64_t,uint32_t > errorCode;
	std::map<uint64_t,std::string > errorMsg;
	std::string outReserve = "";		
	CStorageAoStub4Web oStub;
	//mock

	FStockSysNo.insert(100);
	// TODO:替换函数参数
    uint32_t dwResult = oStub.DeleteStock(
		oCntlInfo,
		machineKey,
		source,
		sceneId,
		option,
		FStockSysNo,
		inReserve,
		errmsg,
		errorCode,
		errorMsg,
		outReserve
  	);
    if(dwResult == 0)
	{
		std::cout << "Invoke OK!" << std::endl;
		printf("OK result[0x%x], time = %ld\n"
        , dwResult, oStub.GetLastConsumeTime());
	}
	else
    {
        printf("Error result[0x%x], time = %ld , errmsg = [%s]\n"
        , dwResult, oStub.GetLastConsumeTime(),oStub.GetLastErrMsg());
    }
}
void TestGetStockByIds()
{
	//TODO 如果使用配置中心来获取APP地址,请注释下行
	//CCGI_STUB_CNTL->setPeerAddr("172.25.34.123", 53101);

	//TODO 请设置用户Passport
	CCntlInfo oCntlInfo;
	oCntlInfo.setOperatorUin(1);
	oCntlInfo.setOperatorClientIP(0);
	oCntlInfo.setOperatorKey("stw3ymf9uk");
	//TODO 请设置路由值
	oCntlInfo.setRouteKey(88883687);
	std::string machineKey = "123";
	std::string source = "123";
	uint32_t sceneId = 123;
	std::set<uint64_t > IDList;
	std::string inReserve = "";		
	std::string errmsg = "";		
	std::vector<erp::storage::po::CStockPo > StockList;
	std::string outReserve = "";		
	CStorageAoStub4Web oStub;
	//mock
	IDList.insert(1);
	IDList.insert(2);
	IDList.insert(100000);
	// TODO:替换函数参数
    uint32_t dwResult = oStub.GetStockBySysNos(
		oCntlInfo,
		machineKey,
		source,
		sceneId,
		IDList,
		inReserve,
		errmsg,
		StockList,
		outReserve
  	);
    if(dwResult == 0)
	{

	    std::vector<erp::storage::po::CStockPo>::const_iterator it = StockList.begin();
	    for (; it != StockList.end(); it++)
	    {
	    	printf ("%s", it->ToString().c_str());
	    }

		std::cout << "Invoke OK!" << std::endl;
		printf("TestGetStockList OK result[0x%x], time = %ld\n"
        , dwResult, oStub.GetLastConsumeTime());
	}
	else
    {
        printf("Error result[0x%x], time = %ld , errmsg = [%s]\n"
        , dwResult, oStub.GetLastConsumeTime(),oStub.GetLastErrMsg());
    }
}
void TestGetStockList()
{
	//TODO 如果使用配置中心来获取APP地址,请注释下行
	//CCGI_STUB_CNTL->setPeerAddr("172.25.34.123", 53101);

	//TODO 请设置用户Passport
	CCntlInfo oCntlInfo;
	oCntlInfo.setOperatorUin(1);
	oCntlInfo.setOperatorClientIP(0);
	oCntlInfo.setOperatorKey("stw3ymf9uk");
	//TODO 请设置路由值
	oCntlInfo.setRouteKey(88883687);
	std::string machineKey = "123";
	std::string source = "123";
	uint32_t sceneId = 123;
	erp::storage::po::CStockFilterPo StockFilter;
	std::string inReserve = "";		
	std::string errmsg = "";		
	uint32_t total = 0;
	std::vector<erp::storage::po::CStockPo > StockList;
	std::string outReserve = "";		
	CStorageAoStub4Web oStub;

	//mork
	StockFilter.dwStockStatus = 1;
	StockFilter.dwPageSize = 5;
	StockFilter.dwPage = 1;
	// TODO:替换函数参数
    uint32_t dwResult = oStub.GetStockList(
		oCntlInfo,
		machineKey,
		source,
		sceneId,
		StockFilter,
		inReserve,
		errmsg,
		total,
		StockList,
		outReserve
  	);
    if(dwResult == 0)
	{

	    std::vector<erp::storage::po::CStockPo>::const_iterator it = StockList.begin();
	    for (; it != StockList.end(); it++)
	    {
	    	printf ("%s", it->ToString().c_str());
	    }

		std::cout << "Invoke OK!" << std::endl;
		printf("TestGetStockList OK result[0x%x], time = %ld\n"
        , dwResult, oStub.GetLastConsumeTime());


	}
	else
    {
        printf("Error result[0x%x], time = %ld , errmsg = [%s]\n"
        , dwResult, oStub.GetLastConsumeTime(),oStub.GetLastErrMsg());
    }
}
void TestUpdateStock()
{
	//TODO 如果使用配置中心来获取APP地址,请注释下行
	//CCGI_STUB_CNTL->setPeerAddr("172.25.34.123", 53101);

	//TODO 请设置用户Passport
	CCntlInfo oCntlInfo;
	oCntlInfo.setOperatorUin(1);
	oCntlInfo.setOperatorClientIP(0);
	oCntlInfo.setOperatorKey("stw3ymf9uk");
	//TODO 请设置路由值
	oCntlInfo.setRouteKey(88883687);
	std::string machineKey = "123";
	std::string source = "123";
	uint32_t sceneId = 123;
	uint32_t option = 0;
	erp::storage::po::CStockPo StockInfo;
	std::string inReserve = "";		
	std::string errmsg = "";		
	std::string outReserve = "";		
	CStorageAoStub4Web oStub;
	//mork
	StockInfo.ddwStockSysNo = 100;
	StockInfo.SetFullName("linfenglee");

	// TODO:替换函数参数
    uint32_t dwResult = oStub.UpdateStock(
		oCntlInfo,
		machineKey,
		source,
		sceneId,
		option,
		StockInfo,
		inReserve,
		errmsg,
		outReserve
  	);
    if(dwResult == 0)
	{
		std::cout << "Invoke OK!" << std::endl;
		printf("OK result[0x%x], time = %ld\n"
        , dwResult, oStub.GetLastConsumeTime());
	}
	else
    {
        printf("Error result[0x%x], time = %ld , errmsg = [%s]\n"
        , dwResult, oStub.GetLastConsumeTime(),oStub.GetLastErrMsg());
    }
}
//测试主函数
int main(int argc, char** argv)
{
	//
	//测试主流程
	// 开发人员可以根据业务需要进行顺序的调整，以期达到更好的测试效果
	// 比如，可以按照插入、选择、修改、选择、删除、选择 顺序进行处理
	//
	Init();
	//TestAddStock();
	//TestUpdateStock();
	//TestDeleteStock();
	TestGetStockByIds();
	//TestGetStockList();

	return 0;
}
